<?php
session_set_cookie_params(0 , '/', '.uread.me');
session_start();
header('Content-Type:text/html; charset=UTF-8');
header("P3P: CP=CAO PSA OUR");
date_default_timezone_set('Asia/ShangHai');

if (isset($_SERVER['SERVER_ADDR']) and (preg_match('/127.0.0.1/', $_SERVER['SERVER_ADDR'])) or (isset($_SERVER['LOCAL_ADDR']) and preg_match('/127.0.0.1/', $_SERVER['LOCAL_ADDR']))) {
	error_reporting(E_ALL & ~E_NOTICE);
} else {
	// 在服务器上关闭错误报告
	error_reporting(0);
	// 如果访问的是ureadme.cn，则跳转到uread.me
	if (preg_match('/ureadme.cn/i', $_SERVER['HTTP_HOST'])) {
		header('Location:http://uread.me');
	}
	// 在error文件夹中记录错误
	function uReadMeErrorHandler ($errno, $errstr, $errfile, $errline, $errcontext) {
		// E_NOTICE 级别错误就不记录了
		// smarty 里的E_WARNING错误不知道如何解决，暂时也不记录了。(Msg: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for)
		if ( ! ($errno == E_NOTICE or preg_match('/smarty3/i', $errfile)) ) {
			$fp = fopen(dirname(__FILE__).'/../error/'.date('Ymd'), 'a');
			$msg = "-------- ".date('Y-m-d H:i:s')." Error Number: $errno ------------------------------------------\r\n";
			$msg .= "File: $errfile, Line: $errline\r\n";
			$msg .= "Msg: $errstr\r\n";
			$msg .= "Context:" . ((is_array($errcontext)) ? print_r($errcontext, true) : $errcontext);
			fwrite($fp, $msg);
			fclose($fp);
		}
	}
	set_error_handler("uReadMeErrorHandler");	
}
require_once(dirname(__FILE__).'/define.php');
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/function.php');
?>